﻿/**
 * auth:zhaowh
 * createdate:2021-09-11
 * description:base class for generator BizForm
 * */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTP.AppFrame.PrototypeTools.Business.Page;
using GTP.AppFrame.PrototypeTools.Common;

namespace GTP.AppFrame.PrototypeTools.Business
{
    /// <summary>
    /// 业务表单
    /// </summary>
    public class BizForm
    {
        /// <summary>
        /// 属性信息，包含主实体和子实体
        /// </summary>
        public BizProperty PropertyInfo { get; set; }

        /// <summary>
        /// 构造函数，所有需要的属性必须满足
        /// </summary>
        /// <param name="BizProperty"></param>
        public BizForm(BizProperty property)
        {
            PropertyInfo = property;
        }
        /// <summary>
        /// 生成业务表单
        /// </summary>
        public void Generate()
        {
            //生成列表页，页面引用查询
            GTPListPage listPage = new GTPListPage();
            listPage.Gennerator(PropertyInfo);
            //生成编辑页，页面引用实体
            GTPEditPage editPage = new GTPEditPage();
            editPage.Gennerator(PropertyInfo);
            //生成业务表单，包含两个页面，一个实体，一个查询，一个表,一个关系图
            Generator();
        }

        /// <summary>
        /// 生成业务表单NameModule.metadata.bizform和NameModule_Diagram
        /// </summary>
        private void Generator()
        {
            string fileName = string.Empty;
            string data = string.Empty;
            //生成bizform
            fileName = string.Format("{0}Module.metadata.bizform", PropertyInfo.Name);
            data = GeneratorUtility.ReadConfigMetadata(GeneratorUtility.ConfigMetadataName.BizForm);
            data = PropertyInfo.Fill(data);
            GeneratorUtility.WriteMetadata(fileName, data);
            //生成Diagram
            fileName = string.Format("{0}Module_Diagram.metadata.diagram", PropertyInfo.Name);
            data = GeneratorUtility.ReadConfigMetadata(GeneratorUtility.ConfigMetadataName.Diagram);
            data = PropertyInfo.Fill(data);
            GeneratorUtility.WriteMetadata(fileName, data);
        }
    }
}
